#!/bin/bash

fileName=$1
ke=""

if [ "$fileName" = "" ]; then
        fileName='./databases.py'
        ke=""
fi

if [ ! -f "$fileName" ]; then
        fileName='./databases.py'
        ke=""
fi

if [ ! -f "$fileName" ]; then
        echo "--file does not exist ,exit shell --"
        ## 文件不存在
        exit
fi

echo "========================"
echo ""

## 全局变量
cutPreValTmp=""
## 以下是函数处理

function funNameGetValue()
{

    ## local 代表局部函数变量
    local infod=$info

    local hostNameDhd=`( echo  ${infod} | awk '{print $3}' | cut -d ';' -f 1 | cut -c 2- )`

    local hostNameLend=$(echo ${hostNameDhd} | wc -L)

    local hostNameLenSubd=$[hostNameLend-1]

    local userNameCutPred=$( echo ${hostNameDhd} | cut -c 1-${hostNameLenSubd})

    ## 覆盖全局变量的值
    cutPreValTmp=${userNameCutPred}

}

## 获取数据库文件的用户名
info=$( grep "config\['hostname'\]" ${fileName}  )
## 写函数名代表调用一次函数
funNameGetValue
## 重新赋值 得到的全局变量值
hostname=${cutPreValTmp}

info=$( grep "config\['username'\]" ${fileName}  )
funNameGetValue
username=${cutPreValTmp}

info=$( grep "config\['password'\]" ${fileName}  )
funNameGetValue
password=${cutPreValTmp}

## 组合 https://www.sojson.com/encrypt_md5.html
mysql -u${username} -p${password} -h${hostname}



<<memo
## 注释 备注 命令
    ## cut 
    ##    https://blog.csdn.net/menlinshuangxi/article/details/7979504
    ## 从一串字符串中获取特定的信息
    ##    https://www.cnblogs.com/yunsicai/p/3745102.html
    ## linux shell提取单引号内的字符串
    ##    https://www.cnblogs.com/luv124/p/13306419.html?utm_source=tuicool
    ##  :Linux中特殊符号
    ##    https://cloud.tencent.com/developer/article/1454832
    ##  linux 获取双引号里的内容
    ##    https://zhidao.baidu.com/question/1494451991793981619.html
    ##    https://zhidao.baidu.com/question/1733259562396603067.html
    ##    https://www.cnblogs.com/hurryup/articles/9184649.html
    ##  Linux下判断字符串长度
    ##    https://www.cnblogs.com/EasonJim/p/8320230.html
    ##    https://www.jb51.net/article/51348.htm
    ##    https://blog.51cto.com/10248921/2159723
    ##  判断字符串为空的方法
    ##    https://zhidao.baidu.com/question/493150149.html
    ##  sed
    ##    https://www.cnblogs.com/ginvip/p/6376049.html
    ##  awk 如果想要把某一文件的总行数赋值给变量nlines
    ##    https://www.cnblogs.com/RandomRand/p/7403239.html
    ##  awk
    ##    https://www.runoob.com/linux/linux-comm-awk.html
    ##  sh 加、减、乘、除
    ##    https://blog.csdn.net/hxpjava1/article/details/80719112
    ##  sh中关于if的用法
    ##    https://zhidao.baidu.com/question/69671581.html
    函数案例备注
        如何获取函数的返回值
            https://blog.csdn.net/qq_31598113/article/details/80611480
    函数
        https://www.cnblogs.com/-beyond/p/8280208.html
        https://blog.csdn.net/taranfly/article/details/80253416
        https://blog.csdn.net/qq_31725371/article/details/83549598?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param
    判断文件/文件夹 是否存在的shell脚本代码！
        https://www.cnblogs.com/weijiangbao/p/7862278.html
    退出整个 shell 脚本
        https://blog.csdn.net/qq_35769944/article/details/81943543



memo


